package com.jinzhi.jzcultivate.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.jzweb.domain.ConsultationsDO;
import com.jinzhi.jzweb.service.*;
import com.jinzhi.sys.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

@Controller
@AllArgsConstructor
@RequestMapping("/wxCode")
public class WxLoginCodeController {

    @Autowired
    private ConsultationsService consultationsService;

    @Autowired
    private CoursesService coursesService;

    @Autowired
    private ExpertsService expertsService;

    @Autowired
    private UserService userService;

    @Autowired
    private LearnRecordService learnRecordService;

    @Autowired
    private OrganizationNewsService organizationNewsService;

    @Autowired
    private OrganizationRolesService organizationRolesService;

    @Autowired
    private ResumesService resumesService;

    @Autowired
    private ApplicationRecordService applicationRecordService;

    @Autowired
    private ChapterService chapterService;

    @Autowired
    private RecruitmentNewsService recruitmentNewsService;

    @Autowired
    private TrainingCertificatesService trainingCertificatesService;


    @Log("登录注册")
    @GetMapping("cultivateLogins")
    String cultivateLogins(Model model, String name) throws UnsupportedEncodingException {  //培训平台登录注册
        String u_name = java.net.URLDecoder.decode(name, "UTF-8");// 解码
        u_name = new String(u_name.getBytes("iso-8859-1"), "utf-8");
        //注册须知
        Wrapper<ConsultationsDO> consultationsDOWrapper = new EntityWrapper<ConsultationsDO>().orderBy("creater_date", false);
        consultationsDOWrapper.eq("first_column", "证书考试门户");
        consultationsDOWrapper.eq("state", 1);
        consultationsDOWrapper.eq("second_column", "注册须知").last("limit 1"); //只查询1条
        List<ConsultationsDO> consultationsDOList = consultationsService.selectList(consultationsDOWrapper);
        model.addAttribute("name", name);
        model.addAttribute("consultations", consultationsDOList);
        String codeimg=null;
        try {
            //配置微信回调
            String urlString = URLEncoder.encode("https://www.jz1x.com/jzApi/wximgCode/wxlogCode", "utf-8");
            codeimg="https://open.weixin.qq.com/connect/qrconnect?appid=wxa5b743d1daed59cc&redirect_uri="+urlString+"&response_type=code&scope=snsapi_login&state=e97555458779708b99b9d40cb49f54245c7500e536445d32#wechat_redirect";

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        model.addAttribute("url", codeimg);
        return "cultivateWeb/wxlogin";
    }


}
